home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / misc / unix / tracker_4_3.lzh / tracker / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-13  |  11.0 KB  |  509 lines

  1. /* display.c 
  2.     vi:se ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: display.c,v 4.0 1994/01/11 17:45:22 espie Exp espie $
  6.  * $Log: display.c,v $
  7.  * Revision 4.0  1994/01/11  17:45:22  espie
  8.  * Major change: does not use sprintf heavily.
  9.  *
  10.  * Revision 1.9  1994/01/09  17:36:22  Espie
  11.  * Generalized open.c.
  12.  *
  13.  * Revision 1.8  1994/01/08  03:55:43  Espie
  14.  * Use name_of_note(), no need for run_in_fg().
  15.  *
  16.  * Revision 1.7  1994/01/08  02:04:21  Espie
  17.  * Small bug: strcpy -> stringcopy.
  18.  *
  19.  * Revision 1.6  1994/01/07  15:06:26  Espie
  20.  * Cond code to make show/not show robust.
  21.  *
  22.  * Revision 1.5  1994/01/06  22:32:42  Espie
  23.  * Added instrument name as shown per display.c.
  24.  *
  25.  * Revision 1.4  1994/01/05  14:54:09  Espie
  26.  * *** empty log message ***
  27.  *
  28.  * Revision 1.3  1994/01/05  01:59:14  Espie
  29.  * Added prototypes.
  30.  *
  31.  * Revision 1.2  1993/12/28  13:54:44  Espie
  32.  * Major change: use scroller interface.
  33.  *
  34.  * Revision 1.1  1993/12/26  00:55:53  Espie
  35.  * Initial revision
  36.  *
  37.  * Revision 1.8  1993/12/04  16:12:50  espie
  38.  * Lots of LOCAL added + minor changes.
  39.  *
  40.  * Revision 1.7  1993/12/02  15:45:33  espie
  41.  * Try to get rid of %d format in printf.
  42.  *
  43.  * Revision 1.6  1993/11/17  15:31:16  espie
  44.  * *** empty log message ***
  45.  *
  46.  * Revision 1.4  1993/07/18  10:39:44  espie
  47.  * Added last displays.
  48.  *
  49.  * Revision 1.3  1993/07/17  22:23:41  espie
  50.  * Fixed bug with bad loops.
  51.  *
  52.  * Revision 1.2  1993/07/17  12:00:30  espie
  53.  * Added other commands (numerous).
  54.  *
  55.  */
  56.      
  57. #include <stdio.h>
  58. #include <string.h>
  59.      
  60. #include "defs.h"
  61. #include "song.h"
  62. #include "channel.h"
  63. #include "extern.h"
  64. #include "tags.h"
  65. #include "prefs.h"
  66.  
  67. ID("$Id: display.c,v 4.0 1994/01/11 17:45:22 espie Exp espie $")
  68. LOCAL void init_display P((void));
  69. LOCAL void (*INIT)P((void)) = init_display;
  70.      
  71. #define ENTRY_SIZE 14
  72. LOCAL char buffer[80];
  73. LOCAL char *base;
  74.  
  75. LOCAL char *num[] = {
  76. " 0", " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9",
  77. "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
  78. "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
  79. "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
  80. "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
  81. "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
  82. "60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
  83. "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
  84. "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
  85. "90", "91", "92", "93", "94", "95", "96", "97", "98", "99",
  86. "00", "01", "02", "03", "04", "05", "06", "07", "08", "09"};
  87.  
  88. char instname[] = { ' ', '1', '2', '3', '4', '5', '6', '7', '9',
  89. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  90. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  91.  
  92. LOCAL void reset_buffer()
  93.    {
  94.    base = new_scroll();
  95.    }
  96.  
  97. LOCAL void next_entry()
  98.    {
  99.    base += ENTRY_SIZE;
  100.    }
  101.  
  102. LOCAL void copy1(to, from)
  103. char *to, *from;
  104.    {
  105.    *to = *from;
  106.    }
  107.    
  108. LOCAL void copy2(to, from)
  109. char *to, *from;
  110.    {
  111.    *to++ = *from++;
  112.    *to = *from;
  113.    }
  114.  
  115. LOCAL void copy3(to, from)
  116. char *to, *from;
  117.    {
  118.    *to++ = *from++;
  119.    *to++ = *from++;
  120.    *to = *from;
  121.    }
  122.  
  123. LOCAL void stringcopy(to, from)
  124. char *to, *from;
  125.    {
  126.    while (*from)
  127.       *to++ = *from++;
  128.    }
  129.  
  130. LOCAL void num2(to, n)
  131. char *to;
  132. int n;
  133.    {
  134.    char *v = num[n];
  135.    *to++ = *v++;
  136.    *to = *v;
  137.    }
  138.  
  139. LOCAL void num3(to, n)
  140. char *to;
  141. int n;
  142.    {
  143.    char *v;
  144.  
  145.    if (n >= 100)
  146.       *to = "0123456789"[n/100];
  147.    while (n > 109)
  148.       n -= 100;
  149.    v = num[n];
  150.    to++;
  151.    *to++ = *v++;
  152.    *to = *v;
  153.    }
  154.  
  155. LOCAL char *id = "$Id: display.c,v 4.0 1994/01/11 17:45:22 espie Exp espie $";
  156.      
  157. LOCAL void (*table[NUMBER_EFFECTS]) P((int samp, int para, int note, struct channel *ch));
  158.  
  159. LOCAL void disp_default(samp, para, note, ch)
  160. int samp, para, note;
  161. struct channel *ch;
  162.    {
  163.    copy3(base+2, name_of_note(note));
  164.    }
  165.  
  166. LOCAL void disp_speed(samp, para, note, ch)
  167. int samp, para, note;
  168. struct channel *ch;
  169.    {
  170.    copy3(base+2, name_of_note(note));
  171.    if (para < 32)
  172.       {
  173.       stringcopy(base+6, "SPD");
  174.       num2(base+10, para);
  175.       }
  176.    else
  177.       {
  178.       stringcopy(base+6, "spd%");
  179.       num3(base+10, para * 100/NORMAL_FINESPEED);
  180.       }
  181.    }
  182.  
  183. LOCAL void disp_nothing(samp, para, note, ch)
  184. int samp, para, note;
  185. struct channel *ch;
  186.    {
  187.    }
  188.  
  189. LOCAL void disp_portamento(samp, para, note, ch)
  190. int samp, para, note;
  191. struct channel *ch;
  192.    {
  193.    stringcopy(base+2, "-->");
  194.    copy3(base+5, name_of_note(note));
  195.    if (para)
  196.       {
  197.       base[8] = '(';
  198.       num3(base+9, para);
  199.       base[12] = ')';
  200.       }
  201.    }
  202.  
  203. LOCAL void disp_portaslide(samp, para, note, ch)
  204. int samp, para, note;
  205. struct channel *ch;
  206.    {
  207.    stringcopy(base+2, "-->");
  208.    copy3(base+5, name_of_note(note));
  209.    if (LOW(para))
  210.       {
  211.       base[9] = '-';
  212.       num2(base+10, LOW(para));
  213.       }
  214.    else
  215.       {
  216.       base[9] = '+';
  217.       num2(base+10, HI(para));
  218.       }
  219.    }
  220.  
  221. LOCAL void disp_upslide(samp, para, note, ch)
  222. int samp, para, note;
  223. struct channel *ch;
  224.    {
  225.    copy3(base+2, name_of_note(note));
  226.    base[8] = '-';
  227.    if (para)
  228.       num3(base+9, para);
  229.    }
  230.  
  231. LOCAL void disp_downslide(samp, para, note, ch)
  232. int samp, para, note;
  233. struct channel *ch;
  234.    {
  235.    copy3(base+2, name_of_note(note));
  236.    base[8] = '+';
  237.    if (para)
  238.       num3(base+9, para);
  239.    }
  240.  
  241. LOCAL void disp_vibrato(samp, para, note, ch)
  242. int samp, para, note;
  243. struct channel *ch;
  244.    {
  245.    copy3(base+2, name_of_note(note));
  246.    copy2(base+6, "vb");
  247.    if (para)
  248.       {
  249.       num2(base+8, LOW(para));
  250.       base[10] = '/';
  251.       num2(base+11, HI(para));
  252.       }
  253.    }
  254.  
  255. LOCAL void disp_vibratoslide(samp, para, note, ch)
  256. int samp, para, note;
  257. struct channel *ch;
  258.    {
  259.    copy3(base+2, name_of_note(note));
  260.    stringcopy(base+6, "vibs");
  261.    if (LOW(para))
  262.       {
  263.       base[10] = '-';
  264.       num2(base+11, LOW(para));
  265.       }
  266.    else
  267.       {
  268.       base[10] = '+';
  269.       num2(base+11, HI(para));
  270.       }
  271.    }
  272.  
  273. LOCAL void disp_slidevol(samp, para, note, ch)
  274. int samp, para, note;
  275. struct channel *ch;
  276.    {
  277.    copy3(base+2, name_of_note(note));
  278.    stringcopy(base+6, "vol");
  279.    if (LOW(para))
  280.       {
  281.       base[10] = '-';
  282.       num2(base+11, LOW(para));
  283.       }
  284.    else
  285.       if (HI(para))
  286.          {
  287.          base[10] = '+';
  288.          num2(base+11, HI(para));
  289.          }
  290.    }
  291.  
  292. LOCAL void disp_volume(samp, para, note, ch)
  293. int samp, para, note;
  294. struct channel *ch;
  295.    {
  296.    copy3(base+2, name_of_note(note));
  297.    if (para)
  298.       {
  299.       stringcopy(base+6, "vol");
  300.       num3(base+10, para);
  301.       }
  302.    else
  303.       stringcopy(base+6, "silent");
  304.    }
  305.  
  306. LOCAL void disp_arpeggio(samp, para, note, ch)
  307. int samp, para, note;
  308. struct channel *ch;
  309.    {
  310.    if (note != NO_NOTE)
  311.       {
  312.       copy3(base+2, name_of_note(note));
  313.       copy3(base+6, name_of_note(note + LOW(para)));
  314.       copy3(base+10, name_of_note(note + HI(para)));
  315.       }
  316.    else
  317.       if (ch->note == NO_NOTE)
  318.          stringcopy(base, "Arp error");
  319.       else
  320.          {
  321.          copy3(base+6, name_of_note(ch->note + LOW(para)));
  322.          copy3(base+10, name_of_note(ch->note + HI(para)));
  323.          }  
  324.    }
  325.  
  326. LOCAL void disp_retrig(samp, para, note, ch)
  327. int samp, para, note;
  328. struct channel *ch;
  329.    {
  330.    copy3(base+2, name_of_note(note));
  331.    stringcopy(base + 6, "rtg");
  332.    num3(base+9, para);
  333.    }
  334.  
  335. LOCAL void disp_note_cut(samp, para, note, ch)
  336. int samp, para, note;
  337. struct channel *ch;
  338.    {
  339.    copy3(base+2, name_of_note(note));
  340.    stringcopy(base+6, "cut");
  341.    num3(base+9, para);
  342.    }
  343.  
  344. LOCAL void disp_late_start(samp, para, note, ch)
  345. int samp, para, note;
  346. struct channel *ch;
  347.    {
  348.    copy3(base+2, name_of_note(note));
  349.    stringcopy(base+6, "lte");
  350.    num3(base+9, para);
  351.    }
  352.  
  353. LOCAL void disp_offset(samp, para, note, ch)
  354. int samp, para, note;
  355. struct channel *ch;
  356.    {
  357.    copy3(base+2, name_of_note(note));
  358.    stringcopy(base+6, "off   %");
  359.    num3(base+9, para * 25600/ch->samp->length);
  360.    }
  361.  
  362. LOCAL void disp_smooth_up(samp, para, note, ch)
  363. int samp, para, note;
  364. struct channel *ch;
  365.    {
  366.    copy3(base+2, name_of_note(note));
  367.    stringcopy(base+6, "sth-");
  368.    num3(base+10, para);
  369.    }
  370.  
  371. LOCAL void disp_smooth_down(samp, para, note, ch)
  372. int samp, para, note;
  373. struct channel *ch;
  374.    {
  375.    copy3(base+2, name_of_note(note));
  376.    stringcopy(base+6, "sth+");
  377.    num3(base+10, para);
  378.    }
  379.  
  380. LOCAL void disp_smooth_upvolume(samp, para, note, ch)
  381. int samp, para, note;
  382. struct channel *ch;
  383.    {
  384.    copy3(base+2, name_of_note(note));
  385.    stringcopy(base+8, "++");
  386.    num3(base+10, para);
  387.    }
  388.  
  389. LOCAL void disp_smooth_downvolume(samp, para, note, ch)
  390. int samp, para, note;
  391. struct channel *ch;
  392.    {
  393.    copy3(base+2, name_of_note(note));
  394.    stringcopy(base+8, "--");
  395.    num3(base+10, para);
  396.    }
  397.  
  398. LOCAL void disp_change_finetune(samp, para, note, ch)
  399. int samp, para, note;
  400. struct channel *ch;
  401.    {
  402.    copy3(base+2, name_of_note(note));
  403.    stringcopy(base+6, "fine");
  404.    num2(base+11, para);
  405.    }
  406.  
  407. LOCAL void disp_skip(samp, para, note, ch)
  408. int samp, para, note;
  409. struct channel *ch;
  410.    {
  411.    copy3(base+2, name_of_note(note));
  412.    if (para)
  413.       {
  414.       stringcopy(base+6, "skp");
  415.       num3(base+10, para);
  416.       }
  417.    else
  418.       stringcopy(base+6, "next");
  419.    }
  420.  
  421. LOCAL void disp_fastskip(samp, para, note, ch)
  422. int samp, para, note;
  423. struct channel *ch;
  424.    {
  425.    copy3(base+2, name_of_note(note));
  426.    stringcopy(base+6, "ff");
  427.    num3(base+10, para);
  428.    }
  429.  
  430. LOCAL void disp_loop(samp, para, note, ch)
  431. int samp, para, note;
  432. struct channel *ch;
  433.    {
  434.    copy3(base+2, name_of_note(note));
  435.    if (para == 0)
  436.       stringcopy(base+6, "SETLOOP");
  437.    else
  438.       {
  439.       stringcopy(base+6, "LOOP");
  440.       num3(base+10, para);
  441.       }
  442.    }
  443.  
  444. LOCAL void disp_delay_pattern(samp, para, note, ch)
  445. int samp, para, note;
  446. struct channel *ch;
  447.    {
  448.    copy3(base+2, name_of_note(note));
  449.    stringcopy(base+6, "DLAY");
  450.    num3(base+10, para);
  451.    }
  452.  
  453. #define disp_nothing disp_default
  454.  
  455. LOCAL void init_display()
  456.    {
  457.    int i;
  458.  
  459.    for (i = 0; i < NUMBER_EFFECTS; i++)
  460.       table[i] = disp_nothing;
  461.    table[EFF_ARPEGGIO] = disp_arpeggio;
  462.    table[EFF_SPEED] = disp_speed;
  463.    table[EFF_SKIP] = disp_skip;
  464.    table[EFF_FF] = disp_fastskip;
  465.    table[EFF_VOLUME] = disp_volume;
  466.    table[EFF_VOLSLIDE] = disp_slidevol;
  467.    table[EFF_OFFSET] = disp_offset;
  468.    table[EFF_PORTA] = disp_portamento;
  469.    table[EFF_PORTASLIDE] = disp_portaslide;
  470.    table[EFF_UP] = disp_upslide;
  471.    table[EFF_DOWN] = disp_downslide;
  472.    table[EFF_VIBRATO] = disp_vibrato;
  473.    table[EFF_VIBSLIDE] = disp_vibratoslide;
  474.    table[EFF_SMOOTH_UP] = disp_smooth_up;
  475.    table[EFF_SMOOTH_DOWN] = disp_smooth_down;
  476.    table[EFF_CHG_FTUNE] = disp_change_finetune;
  477.    table[EFF_LOOP] = disp_loop;
  478.    table[EFF_RETRIG] = disp_retrig;
  479.    table[EFF_S_UPVOL] = disp_smooth_upvolume;
  480.    table[EFF_S_DOWNVOL] = disp_smooth_downvolume;
  481.    table[EFF_NOTECUT] = disp_note_cut;
  482.    table[EFF_LATESTART] = disp_late_start;
  483.    table[EFF_DELAY] = disp_delay_pattern;
  484.    reset_buffer();
  485.    }
  486.  
  487. void dump_event(ch, e)
  488. struct channel *ch;
  489. struct event *e;
  490.    {
  491.    INIT_ONCE;
  492.    
  493.    if (get_pref_scalar(PREF_SHOW))
  494.       {
  495.       if (ch && base)
  496.          {
  497.          *base = instname[e->sample_number];
  498.          (*table[e->effect])(e->sample_number, e->parameters, e->note, ch);
  499.          next_entry();
  500.          }
  501.       else
  502.          {
  503.          scroll();
  504.          reset_buffer();
  505.          }
  506.       }
  507.    }
  508.  
  509.